package com.base.common.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * User: jay.zhoujingjie
 * Date: 13-12-31
 * Time: 下午2:48
 */
public class LogFactoryUtils
{


    /**
     *
     * @param cls  "class cls"
     * @return
     */
    public static Log getLog(Class cls){
        return LogFactory.getLog(cls);
    }

    /**
     * 返回LOG
     * @param className  "com.domain.className"
     * @return
     * @author jay.zhoujingjie
     */
    public static Log getLog(String className){
        return LogFactory.getLog(className);
    }
    
    /**
     * 获取异常堆栈信息
     * @param throwable
     * @return
     */
    public static String getPrintStackException(Throwable throwable){
    	String result="";
    	StringWriter sw=new StringWriter();
    	PrintWriter pw=new PrintWriter(sw);
    	try {
    		sw=new StringWriter();
    		pw=new PrintWriter(sw);
    		throwable.printStackTrace(pw);
        	result=sw.toString();
    	} finally{
    		try {
    			if(sw != null){
        			sw.flush();
        			sw.close();
        		}
    			if(pw != null){
    				pw.flush();
    				pw.close();
    			}
    		} catch (Exception e){
    			e.printStackTrace();
    		}
    		
    	}  
    	return result;
    }

}
